package com.foto;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import com.camarasmactel.MenuPrincipal;
import com.conexion.Utilitario;

import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

public class ObtenerFoto extends Thread{

	String ruta="";
	
	public ObtenerFoto(){
		
		//pd = ProgressDialog.show(act.getWindow().getContext(), "Conectando...", "Conectando...");
	}
	
	public ObtenerFoto(String ruta){
		
		this.ruta = ruta;
	}
	
	public Bitmap  bmImg;
	Utilitario util = new Utilitario();
	Foto act = new Foto();
	ProgressDialog pd;
	String cadena = "http://"+MenuPrincipal.dns+":"+MenuPrincipal.puerto+"/tmpfs/auto.jpg";
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
	//	super.run();
		
	//	pd = ProgressDialog.show(act.getWindow().getContext(), "Conectando...", "Conectando...");
		URL myFileUrl =null;  
		
	//	cadena = cadena+ruta;
		
	//	Log.i("Cadena", " "+cadena);	
		
        try {
             myFileUrl= new URL(cadena);
        } catch (MalformedURLException e) {
             // TODO Auto-generated catch block
        //    util.mensaje("Revise si la cámara está encendida", act.getParent()); 
           // Log.i("Llega17", "llega 17");
            e.printStackTrace();
        }
        try {
         //    Log.i("Llega1", "llega 1 "+cadena);
      	   HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
      	 //  Log.i("Llega2", "llega 2");
      	   conn.setDoInput(true);
      	//   Log.i("Llega3", "llega 3");
      	   conn.connect();
      	 //  Log.i("Llega4", "llega 4");
             InputStream is = conn.getInputStream();
        //     Log.i("Llega5", "llega 5");
            bmImg  = BitmapFactory.decodeStream(is);
           Log.i("Llega6", "llega 6");
       //    pd.dismiss();
           conn.disconnect();
        
        } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
             Log.i("Llega7", "llega 7");
             //util.mensaje("Revise si la conexión a Internet", act.getParent());
             
        }
           
	}

}
